/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2025 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
typedef struct
{
    uint32_t TimeStart;
    uint32_t TimeInter;
} tsTimeType;

/* USER CODE END ET */

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */

/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */

/* USER CODE END EM */

/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);

/* USER CODE BEGIN EFP */

/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
#define SERVO_PWR_CTRL_Pin GPIO_PIN_4
#define SERVO_PWR_CTRL_GPIO_Port GPIOE
#define BEEP_Pin GPIO_PIN_3
#define BEEP_GPIO_Port GPIOA
#define key1_Pin GPIO_PIN_13
#define key1_GPIO_Port GPIOD
#define led_run_Pin GPIO_PIN_7
#define led_run_GPIO_Port GPIOC
#define led_rx_Pin GPIO_PIN_8
#define led_rx_GPIO_Port GPIOC
#define led_tx_Pin GPIO_PIN_9
#define led_tx_GPIO_Port GPIOC
#define UART5_TX_EN_Pin GPIO_PIN_15
#define UART5_TX_EN_GPIO_Port GPIOA
#define UART5_RX_EN_Pin GPIO_PIN_0
#define UART5_RX_EN_GPIO_Port GPIOD

/* USER CODE BEGIN Private defines */
#define SERVO_MOVE_TIME_WRITE 		0x01	//控制舵机角度指令
#define SERVO_MOVE_TIME_WRITE_LEN	0x07	//指令数据长度
#define SERVO_POS_READ 				0x1C	//读取舵机角度指令
#define SERVO_POS_READ_LEN			0x03	//指令数据长度
#define SERVO_POS_READ_RES_LEN		0x05	//响应数据长度

#define ServoNum		6	//舵机数量
#define CmdMaxLength 	10	//指令帧最大长度
#define	ResMaxLength 	10	//舵机响应最大长度

extern uint8_t UART5Rec_Flag;
extern uint8_t	ServoCmd[CmdMaxLength];
extern uint8_t ServoRes[ResMaxLength];
#define UART5_TX_ENABLE() do { \
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET); \
    HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_RESET); \
} while(0)

#define UART5_RX_ENABLE() do { \
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET); \
    HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_SET); \
} while(0)

#define UART5_DIR_IDLE() do { \
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET); \
    HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_RESET); \
} while(0)
/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
